package com.situ.day717;

import org.junit.Test;

import java.util.Scanner;


public class homework {
    public static void main(String[] args) {
        System.out.println("hello world!");
    }

    @Test
    public void test0(){
        //1、计算某年是不是闰年：
        //能被4整除，但是不能被100整除    ||   能被400整除
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您要计算的年份");
        int year = scanner.nextInt();
        if ((year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)){
            System.out.println("您输入的年份是闰年");
        } else if (year %100 == 0 && year % 400 !=0) {
            System.out.println("您输入的年份是平年");
        }else {
            System.out.println("您输入的年份是平年");
        }
    }

    @Test
    public void test00(){
        //3、计算1-100以内所有奇数的和以及所有偶数的和，分别打印出来。
        int jisum = 0;
        int ousum = 0;
        for (int i = 1; i <=100 ; i++) {
            if (i % 2 == 1){
                jisum += i;
            } else if (i % 2 ==0) {
                ousum += i;
            }
        }
        System.out.println("奇数和为：" + jisum);
        System.out.println("偶数和为：" + ousum);
    }

    @Test
    public void test1(){
        /*1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        求出上面数组中0-9分别出现的次数*/
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int [] count = new int[10];
        for (int score : scores) {
            count[score]++;
        }
        for (int i = 0;i < count.length;i++){
            System.out.println("数字"+i+"出现的次数："+count[i]);
        }
    }

    @Test
    public void test2(){
        //2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        //要求求出其中的奇数个数和偶数个数。
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int cji=0,cou=0;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i]%2==1){
                cji++;
            } else if (scores[i]%2==0) {
                cou++;
            }
        }
        System.out.println("其中奇数的个数是："+cji);
        System.out.println("其中偶数的个数是："+cou);
    }

    @Test
    public void test12(){
        //12、题目：一个任意一个字符串，判断它是不是回文。
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str = scanner.next();
        char[] array = str.toCharArray();
        boolean HuiWen = true;
        for (int i = 0;i < array.length/2;i++){
            if(array[i] != array[array.length - 1 - i]){
                HuiWen =false;
                break;
            }
        }
        if (HuiWen == false){
            System.out.println("不是回文");
        }else {
            System.out.println("是回文");
        }
    }

    @Test
    public void test13(){
        //13、输入一行字符串，分别统计出其中英文字母、空格、数字和其它字符的个数。
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入一行字符串:");
        String str = scanner.nextLine();
        char[] array = str.toCharArray();
        //"dsfhi 34**DSD [34"
        int spacecount = 0;
        int numcount = 0;
        int othercount = 0;
        int lettercount = 0;
        for (char i : array) {
            if((i >= 'a' && i <= 'z') || (i >='A' && i <= 'Z')){
                lettercount++;
            } else if (i >= '0' && i <= '9') {
                numcount++;
            } else if (i == ' ')  {
                spacecount++;
            }else {
                othercount++;
            }
        }
        System.out.println("英文字母的个数是：" + lettercount);
        System.out.println("空格的个数是：" + spacecount);
        System.out.println("数字的个数是：" + numcount);
        System.out.println("其他字符的个数是：" + othercount);
    }
}